package ca.llsutherland.squash.domain.helper;

import ca.llsutherland.squash.domain.Administrator;
import ca.llsutherland.squash.domain.Clock;
import ca.llsutherland.squash.domain.Racquet;
import ca.llsutherland.squash.exceptions.ValidationException;
import ca.llsutherland.squash.utils.ErrorConstants;

public class RacquetsHelper {

    public static Racquet createNewRacquet(String brand, String model, Clock dateCreated, Clock dateUpdated, Administrator createdBy, Long id) {
        Racquet racquet = createUnpersistedRacquet(brand, model, dateCreated, dateUpdated, createdBy);
        racquet.setId(id);
        return racquet;
    }

    public static Racquet createUnpersistedRacquet(String brand, String model, Clock dateCreated, Clock dateUpdated, Administrator createdBy) {
        Racquet racquet = new Racquet();
        racquet.setBrand(brand);
        racquet.setModel(model);
        racquet.setDateCreated(dateCreated);
        racquet.setDateUpdated(dateUpdated);
        racquet.setCreatedBy(createdBy);
        return racquet;
    }

    public static void assertNewValid(Racquet racquet) {
        DomainObjectHelper.assertNotNullWithErrorMessage(racquet, ErrorConstants.NULL_RACQUET_ERROR);
        NamedDomainObjectHelper.assertValidName(racquet.getBrand());
        NamedDomainObjectHelper.assertValidName(racquet.getModel());
        if(racquet.getCreatedBy() == null) {
            throw new ValidationException(ErrorConstants.NULL_ADMINISTRATOR_ERROR);
        }
        
    }


}
